package com.atguigu.guli.edu.controller.admin;

import com.atguigu.common_utils.utils.PageUtils;
import com.atguigu.guli.edu.entity.Video;
import com.atguigu.guli.edu.service.EduVideoService;
import com.atguigu.guli.service.base.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 课程视频
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-01-19 10:59:18
 */
@Api(tags = "课时管理")

@RestController
@RequestMapping("/admin/edu/video")
public class AdminVideoController {
    @Autowired
    private EduVideoService VideoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("edu:eduvideo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = VideoService.queryPage(params);

        return R.ok().data("page", page);
    }

    //保存视频信息
    @ApiOperation("章节信息添加")
    @PostMapping("/save")
    public R save(@RequestBody Video video){
        VideoService.save(video);
        return R.ok();
    }

    @ApiOperation("章节信息修改")
    @PutMapping("/update")
    public R update(@RequestBody Video video){
        VideoService.updateById(video);
        return R.ok();
    }

    @ApiOperation("根据id查询课时")
    @GetMapping("/select/{id}")
    public R selectId(@PathVariable("id")String id){
        Video video = VideoService.getById(id);
        return R.ok().data("data",video);
    }

    @ApiOperation("删除课时")
    @DeleteMapping("/delete/{id}")
    public R deleteId(@PathVariable("id")String id){
        VideoService.removeById(id);
        return R.ok();
    }

}
